package com.family.web.controller.pedigree;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.family.common.core.domain.AjaxResult;
import com.family.pedigree.domain.FamilyLifeShow;
import com.family.pedigree.service.IFamilyLifeShowService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author forever
 * Date 2025/3/12 23:51
 * desc 生活剪影
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/family/life")
public class FamilyLifeShowController {

    private final IFamilyLifeShowService familyLifeShowService;

    /**
     * 保存
     */
    @PostMapping
    public AjaxResult add(@RequestBody FamilyLifeShow lifeShow) {
        familyLifeShowService.save(lifeShow.setCreateTime(LocalDateTime.now()));
        return AjaxResult.success();
    }

    @GetMapping("/node/{nodeId}")
    public AjaxResult getList(Long nodeId) {
        return AjaxResult.success(familyLifeShowService.list(Wrappers.<FamilyLifeShow>lambdaQuery().eq(FamilyLifeShow::getNodeId, nodeId)));
    }

    @DeleteMapping("/{id}")
    public AjaxResult delById(@PathVariable Long id) {
        familyLifeShowService.removeById(id);
        return AjaxResult.success();
    }

}
